const axios = require('axios')
const { appId, appsecret } = require('../uteil')

/**
 * @code 前端传来的用户code,用来获取用户accessToken
 * 获取用户accessToken并判断是否有效
 */
const getUserAccEssToken = async code => {

    let result = await axios.get(`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appId}&secret=${appsecret}&code=${code}&grant_type=authorization_code`)
    console.log('请求用户的accessToken：', result.data);

    result = await axios.get(`https://api.weixin.qq.com/sns/auth?access_token=${result.data.access_token}&openid=${result.data.openid}`)
    console.log('用户的accessToken是否有效：', result.data);

}

module.exports = {
    getUserAccEssToken
}